const { observable, computed, action, autorun } = require('mobx');

class Store {
  @observable array = [];
  @observable obj = {};
  @observable map = new Map();

  @observable string = 'hello';
  @observable number = 20;
  @observable bool = false;

  // computed可以返回多个值的混合值，当里面任何一个值发生变化时会触发一次事件。
  @computed get mix() {
    return this.number + '/' + this.string;
  }

  // action 可以合并设置，这里调用了两次赋值，只会触发一次事件。
  @action setValue(num, str) {
    this.number = num;
    this.string = str;
  }
}

var store = new Store();

// var foo = computed(function () {
//   return store.string + '/' + store.number;
// });

// console.log(foo.get());

// foo.observe_((change) => {
//   console.log(change);
// });

autorun(
  () => store.mix,
  () => {
    console.log('autorun:' + store.string + '/' + store.number);
  }
);

store.number = 30;
store.string = 'world';
